package gqz.mvvm.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.android.databinding.library.baseAdapters.BR;

import java.util.ArrayList;

import gqz.mvvm.R;
import gqz.mvvm.adapter.MyBaseAdapter;
import gqz.mvvm.model.ItemString;
import gqz.mvvm.view.SideSlipItem.SideSlipItemActivity;
import me.everything.android.ui.overscroll.IOverScrollDecor;
import me.everything.android.ui.overscroll.IOverScrollUpdateListener;
import me.everything.android.ui.overscroll.OverScrollDecoratorHelper;
import me.everything.android.ui.overscroll.VerticalOverScrollBounceEffectDecorator;
import me.everything.android.ui.overscroll.adapters.AbsListViewOverScrollDecorAdapter;

//import gqz.mvvm.BR;

/**
 * Created by Administrator on 2017/11/29.
 */

public class HomeActivity extends BaseActivity implements MyBaseAdapter.MyItemClickListener {

    private final String TAG = "HomeActivity---";

    private ListView lv;
    private TextView tv;

    private MyBaseAdapter<ItemString> adapter;

    private ArrayList<ItemString> menulist = new ArrayList<>();
    private String[] data = {"LoginDemo", "GridViewDemo", "ViewPagerDemo", "ProgressBarDemo", "HeartLayout", "AnimatorDemo",
            "PathDemo", "PickerDemo", "PunchDemo", "SideSlipItemDemo", "FadeOutTextDemo", "MySwitch", "Glide", "Matrix", "Sort"};//8
    private Class[] classes = {LoginActivity.class, GridViewActivity.class, ViewPagerActivity.class, ProgressBarActivity.class,
            HeartActivity.class, AnimatorActivity.class, PathActivity.class, PickerActivity.class, PunchActivity.class,
            SideSlipItemActivity.class, FadeOutTextActivity.class, MySwitchActivity.class, GlideActivity.class, MatrixActivity.class,
            SortActivity.class};

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        tv = (TextView) findViewById(R.id.home_tv);
        adapter = new MyBaseAdapter<>(HomeActivity.this, R.layout.item_listview, menulist, BR.txt, this);
        lv = (ListView) findViewById(R.id.home_lv);
        OverScrollDecoratorHelper.setUpOverScroll(lv);
        VerticalOverScrollBounceEffectDecorator decor = new VerticalOverScrollBounceEffectDecorator(new AbsListViewOverScrollDecorAdapter(lv), 2f,// Default is 3f
                VerticalOverScrollBounceEffectDecorator.DEFAULT_TOUCH_DRAG_MOVE_RATIO_BCK,
                VerticalOverScrollBounceEffectDecorator.DEFAULT_DECELERATE_FACTOR);

        decor.setOverScrollUpdateListener(new IOverScrollUpdateListener() {
            @Override
            public void onOverScrollUpdate(IOverScrollDecor decor, int state, float offset) {
                final View view = decor.getView();
                tv.setText("Offset:" + offset);
                if (offset > 0) {
                    // '视图'目前正在从顶部过度滚动。
                } else if (offset < 0) {
                    // '视图'目前正在从底部过度滚动。
                } else {
                    // 没有过度滚动效果。
                    // 和(state == STATE_IDLE)相同.
                }
            }
        });

        lv.setDividerHeight(0);
        lv.setAdapter(adapter);

        for (int i = 0; i < data.length; i++) {
//            menulist.add(new ItemString("String item " + i));
            menulist.add(new ItemString(data[i]));
        }
    }

    @Override
    public void onItemClick(View view) {
        int pos = (int) view.getTag();
        Log.v("HomeActivity", "onItemClick: " + pos);
        startActivity(new Intent(HomeActivity.this, classes[pos]));
    }

}
